package com.bubblegumproject.ogo.swing.events;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Condition triggered when a user double clicks on a JComponent.
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class DoubleClickedCondition extends AbstractCondition {

    public DoubleClickedCondition(JComponent component) {
        assert(component != null);
        component.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) occured();
            }
        });
    }

    public static DoubleClickedCondition DoubleClicked(JComponent component) {
        return new DoubleClickedCondition(component);
    }
}
